package com.xbts.web.controller.cloud;

import com.huaweicloud.sdk.ecs.v2.model.ListServerBlockDevicesRequest;
import com.huaweicloud.sdk.ecs.v2.model.ListServersDetailsResponse;
import com.huaweicloud.sdk.ecs.v2.model.ShowServerRequest;
import com.huaweicloud.sdk.ecs.v2.model.ShowServerResponse;
import com.huaweicloud.sdk.eip.v2.model.ListPublicipsRequest;
import com.huaweicloud.sdk.eip.v2.model.ShowBandwidthRequest;
import com.huaweicloud.sdk.eip.v2.model.UpdateBandwidthRequest;
import com.huaweicloud.sdk.eip.v2.model.UpdatePrePaidBandwidthRequest;
import com.huaweicloud.sdk.eip.v3.model.DisassociatePublicipsRequest;
import com.huaweicloud.sdk.evs.v2.model.CreateVolumeRequest;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.system.domain.dto.*;
import com.xbts.system.service.ICloudControlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 华为云服务器控制
 * @Author llk
 * @Date 2023/8/7 9:49
 */
@RestController
@RequestMapping("/cloud/control")
public class CloudControlController extends BaseController {

    @Autowired
    private ICloudControlService cloudControlService;


    /**
     * 查询云服务器详情列表
     * @param listServersDetailsRequest 请求参数
     * @return 云服务器详情列表
     */
    @PostMapping("/listServersDetails")
    public AjaxResult listServersDetails(@RequestBody ListServersDetailsRequestDTO listServersDetailsRequest) {
        ListServersDetailsResponse response = cloudControlService.listServersDetails(listServersDetailsRequest);
        if (response != null) {
            return AjaxResult.success(response);
        } else {
            return AjaxResult.error("查询云服务器详情列表失败");
        }
    }

    /**
     * 查询云服务器详情列表
     * @param regionIdDTO 请求参数
     * @return 云服务器详情列表
     */
    @PostMapping("/showServer")
    public AjaxResult showServer(@RequestBody RegionIdDTO<ShowServerRequest> regionIdDTO) {
        ShowServerResponse response = cloudControlService.showServer(regionIdDTO);
        if (response != null) {
            return AjaxResult.success(response);
        } else {
            return AjaxResult.error("查询云服务器详情失败");
        }
    }

    /**
     * 批量关闭云服务器
     * @param batchStopServersRequestBodyDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/batchStopServers")
    public AjaxResult batchStopServers(@RequestBody BatchStopServersRequestBodyDTO batchStopServersRequestBodyDTO) {
        return cloudControlService.batchStopServers(batchStopServersRequestBodyDTO);
    }

    /**
     * https://support.huaweicloud.com/api-ecs/ecs_02_0301.html
     * 批量启动云服务器
     * @param batchStartServersRequestBody 请求参数
     * @return 操作结果
     */
    @PostMapping("/batchStartServers")
    public AjaxResult batchStartServers(@RequestBody BatchStartServersRequestBodyDTO batchStartServersRequestBody) {
        return cloudControlService.batchStartServers(batchStartServersRequestBody);
    }

    /**
     * 批量重启云服务器
     * @param batchRebootServersRequestBodyDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/batchRebootServers")
    public AjaxResult batchRebootServers(@RequestBody BatchRebootServersRequestBodyDTO batchRebootServersRequestBodyDTO) {
        return cloudControlService.batchRebootServers(batchRebootServersRequestBodyDTO);
    }

    /**
     * 批量修改弹性云服务器
     * @param batchUpdateServersNameRequestBodyDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/batchUpdateServersName")
    public AjaxResult batchUpdateServersName(@RequestBody BatchUpdateServersNameRequestBodyDTO batchUpdateServersNameRequestBodyDTO) {
        return cloudControlService.batchUpdateServersName(batchUpdateServersNameRequestBodyDTO);
    }

    /**
     * 批量重置弹性云服务器密码
     * @param batchResetServersPasswordRequestBodyDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/batchResetServersPassword")
    public AjaxResult batchResetServersPassword(@RequestBody BatchResetServersPasswordRequestBodyDTO batchResetServersPasswordRequestBodyDTO) {
        return cloudControlService.batchResetServersPassword(batchResetServersPasswordRequestBodyDTO);
    }

    /**
     * https://support.huaweicloud.com/api-ecs/ecs_02_0208.html
     * 获取VNC远程登录地址
     * @param showServerRemoteConsoleRequestDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/showServerRemoteConsole")
    public AjaxResult showServerRemoteConsole(@RequestBody ShowServerRemoteConsoleRequestDTO showServerRemoteConsoleRequestDTO) {
        return cloudControlService.showServerRemoteConsole(showServerRemoteConsoleRequestDTO);
    }
    /**
     * https://support.huaweicloud.com/api-oce/api_order_00018.html
     * 续订包年/包月资源
     * @param renewalResourcesReqDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/renewalResources")
    public AjaxResult renewalResources(@RequestBody RenewalResourcesReqDTO renewalResourcesReqDTO) {
        return cloudControlService.renewalResources(renewalResourcesReqDTO);
    }
    /**
     * https://support.huaweicloud.com/api-ecs/ecs_02_0602.html
     * 查询弹性云服务器单个磁盘信息
     * @param showServerBlockDeviceRequestDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/showServerBlockDevice")
    public AjaxResult showServerBlockDevice(@RequestBody ShowServerBlockDeviceRequestDTO showServerBlockDeviceRequestDTO) {
        return cloudControlService.showServerBlockDevice(showServerBlockDeviceRequestDTO);
    }
    /**
     * https://support.huaweicloud.com/api-ecs/ecs_02_0604.html
     * 查询弹性云服务器磁盘信息
     * @param listServerBlockDevicesRequest 请求参数
     * @return 操作结果
     */
    @PostMapping("/listServerBlockDevices")
    public AjaxResult listServerBlockDevices(@RequestBody ListServerBlockDevicesRequest listServerBlockDevicesRequest) {
        return cloudControlService.listServerBlockDevices(listServerBlockDevicesRequest);
    }

    /**
     * https://support.huaweicloud.com/api-ecs/ecs_02_0606.html
     * 弹性云服务器卸载磁盘
     * @param detachServerVolumeRequestDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/detachServerVolume")
    public AjaxResult detachServerVolume(@RequestBody DetachServerVolumeRequestDTO detachServerVolumeRequestDTO) {
        return cloudControlService.detachServerVolume(detachServerVolumeRequestDTO);
    }

    /**
     * https://support.huaweicloud.com/api-ecs/ecs_02_0605.html
     * 弹性云服务器挂载磁盘
     * @param attachServerVolumeRequestDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/attachServerVolume")
    public AjaxResult attachServerVolume(@RequestBody AttachServerVolumeRequestDTO attachServerVolumeRequestDTO) {
        return cloudControlService.attachServerVolume(attachServerVolumeRequestDTO);
    }

    /**
     * https://support.huaweicloud.com/api-ecs/ecs_02_0202.html
     * 切换弹性云服务器操作系统(安装Cloud init)
     * @param changeServerOsWithCloudInitRequestDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/changeServerOsWithCloudInit")
    public AjaxResult changeServerOsWithCloudInit(@RequestBody ChangeServerOsWithCloudInitRequestDTO changeServerOsWithCloudInitRequestDTO) {
        return cloudControlService.changeServerOsWithCloudInit(changeServerOsWithCloudInitRequestDTO);
    }

    /**
     * https://support.huaweicloud.com/api-ecs/ecs_02_0201.html
     * 重装弹性云服务器操作系统（安装Cloud-init）
     * @param reinstallServerWithCloudInitRequestDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/reinstallServerWithCloudInit")
    public AjaxResult reinstallServerWithCloudInit(@RequestBody ReinstallServerWithCloudInitRequestDTO reinstallServerWithCloudInitRequestDTO) {
        return cloudControlService.reinstallServerWithCloudInit(reinstallServerWithCloudInitRequestDTO);
    }

    /**
     * https://support.huaweicloud.com/api-eip/DisassociatePublicips.html
     * 解绑弹性公网IP
     * @param regionIdDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/disassociatePublicips")
    public AjaxResult disassociatePublicips(@RequestBody RegionIdDTO<DisassociatePublicipsRequest> regionIdDTO) {
        return cloudControlService.disassociatePublicips(regionIdDTO);
    }

    /**
     * https://support.huaweicloud.com/api-eip/eip_apisharedbandwidth_0006.html
     * 更新包周期带宽
     * @param regionIdDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/updatePrePaidBandwidth")
    public AjaxResult updatePrePaidBandwidth(@RequestBody RegionIdDTO<UpdatePrePaidBandwidthRequest> regionIdDTO) {
        return cloudControlService.updatePrePaidBandwidth(regionIdDTO);
    }
    @PostMapping("/showBandwidth")
    public AjaxResult showBandwidth(@RequestBody RegionIdDTO<ShowBandwidthRequest> regionIdDTO) {
        return cloudControlService.showBandwidth(regionIdDTO);
    }

    /**
     * 查询弹性公网IP列表
     * @param regionIdDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/listPublicips")
    public AjaxResult listPublicips(@RequestBody RegionIdDTO<ListPublicipsRequest> regionIdDTO) {
        return AjaxResult.success(cloudControlService.listPublicips(regionIdDTO));
    }
    /**
     * https://support.huaweicloud.com/api-ecs/ecs_02_0402.html
     * 查询云服务器规格变更支持列表
     * @param regionIdDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/listResizeFlavors")
    public AjaxResult listResizeFlavors(@RequestBody RegionIdDTO<UpdatePrePaidBandwidthRequest> regionIdDTO) {
        return cloudControlService.listResizeFlavors(regionIdDTO);
    }
    /**
     * https://support.huaweicloud.com/api-vpc/vpc_api01_0003.html
     * 查询VPC列表
     * @param regionIdDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/listVpcs")
    public AjaxResult listVpcs(@RequestBody RegionIdDTO<UpdatePrePaidBandwidthRequest> regionIdDTO) {
        return AjaxResult.success(cloudControlService.listVpcs(regionIdDTO));
    }

    /**
     * https://support.huaweicloud.com/api-evs/evs_04_2003.html
     * 创建云硬盘
     * @param regionIdDTO 请求参数
     * @return 操作结果
     */
    @PostMapping("/createVolume")
    public AjaxResult createVolume(@RequestBody RegionIdDTO<CreateVolumeRequest> regionIdDTO) {
        return AjaxResult.success(cloudControlService.createVolume(regionIdDTO));
    }
}
